import { EnumBetResult, EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RecmInfo, RoundInfo } from "../ExecutePlan";
import { IRecmStrategy } from "../IRecmStrategy";

export interface IFixedStrategy {
    reverse: boolean;
}
export class FixedStrategy implements IRecmStrategy {
    strategyName: string = "FixedStrategy";
    debugCompoenent: string = "";
    option: IFixedStrategy;
    constructor(option?: IFixedStrategy) {
        if (option) {
            this.option = option;
        }
        else {
            this.option = {
                reverse: false
            };
        }
    }
    resetRecm(): void {
    }
    copyValue(valueObj: any): void {
        let obj = valueObj as FixedStrategy;
        if (obj) {
            this.strategyName = obj.strategyName;
            this.debugCompoenent = obj.debugCompoenent;
            Object.assign(this.option, obj.option);
        }
    }
    setOption<T>(option: T): void {
        return;
    }
    setResult(roundInfo: RoundInfo, recmInfo: RecmInfo, multiple: number, waterRate: number, fuliRate: number): void {
        //recmInfo.summaryInfo.updateSummaryInfo(roundInfo.currentResult, recmInfo.recmV, multiple, waterRate, fuliRate);
    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        //throw new Error("Method not implemented.");
        let recmV = EnumBjlResult.U;
        if (roundInfo.userRecm != EnumBjlResult.U) {
            recmV = roundInfo.userRecm;
            if (this.option.reverse) {
                recmV = roundInfo.userRecm == EnumBjlResult.Z ? EnumBjlResult.X : EnumBjlResult.Z;
            }
        }

        return recmV;
    }

}


export interface IFixedResultStrategy {
    reverse: boolean;
    followResultCount: number;
}

export class FixedResultStrategy extends FixedStrategy {
    protected _followResultCount: number = 0;
    public get followResultCount(): number { return this._followResultCount; }

    protected _reverse: boolean = false;

    public get reverse(): boolean { return this._reverse; }

    constructor(option?: IFixedResultStrategy) {
        super(option);
        this.strategyName = "FixedResultStrategy";
        if (option) {
            this._followResultCount = option.followResultCount;
            this._reverse = option.reverse;
        }
        else {
            this._followResultCount = 1;
            this._reverse = false;
        }
    }

    toResult(roundInfo: RoundInfo): EnumBjlResult {
        //throw new Error("Method not implemented.");
        let recmV = EnumBjlResult.U;
        if (this._followResultCount < roundInfo.results.length) {
            recmV = roundInfo.results[roundInfo.results.length - this._followResultCount];
        }

        if (recmV != EnumBjlResult.U) {
            if (recmV == roundInfo.currentResult) {
                recmV = roundInfo.userRecm;
            }
            else {
                recmV = recmV == EnumBjlResult.Z ? EnumBjlResult.X : EnumBjlResult.Z;
            }
        }


        return recmV;
    }
}
export interface IFixedValueStrategy extends IFixedStrategy {
    result: EnumBjlResult;

}
export class FixedValueStrategy extends FixedStrategy {
    protected _result: EnumBjlResult;
    constructor(option?: IFixedValueStrategy) {
        super(option);
        if (option) {
            this._result = option.result;
        }
        else {

            this._result = EnumBjlResult.Z;
        }

    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        let recmV = this._result;
        if (this.option.reverse && recmV != EnumBjlResult.U) {
            recmV = roundInfo.userRecm == EnumBjlResult.Z ? EnumBjlResult.X : EnumBjlResult.Z;
        }

        return recmV;
    }
}